package com.kexio.pay.provider;

import java.util.Map;
import java.util.Set;

import com.kexio.pay.dto.PaymentRequest;
import com.kexio.pay.dto.PaymentResponse;
import com.kexio.pay.entity.PaymentCallback;
import com.kexio.pay.enums.PaymentMethod;
import com.kexio.pay.enums.PaymentStatus;

/**
 * 支付提供商接口
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public interface PaymentProvider {
    
    /**
     * 获取提供商标识
     * 
     * @return 提供商标识 (wechat, alipay, unionpay等)
     */
    String getProviderId();
    
    /**
     * 获取提供商名称
     * 
     * @return 提供商名称
     */
    String getProviderName();
    
    /**
     * 获取支持的支付方式
     * 
     * @return 支付方式集合
     */
    Set<PaymentMethod> getSupportedMethods();
    
    /**
     * 检查是否支持指定的支付方式
     * 
     * @param method 支付方式
     * @return 是否支持
     */
    boolean isSupported(PaymentMethod method);
    
    /**
     * 创建支付订单
     * 
     * @param request 支付请求
     * @return 支付响应
     */
    PaymentResponse createPayment(PaymentRequest request);
    
    /**
     * 查询支付状态
     * 
     * @param orderNo 系统订单号
     * @param thirdPartyOrderNo 第三方订单号
     * @return 支付状态
     */
    PaymentStatus queryPayment(String orderNo, String thirdPartyOrderNo);
    
    /**
     * 关闭支付订单
     * 
     * @param orderNo 系统订单号
     * @param thirdPartyOrderNo 第三方订单号
     * @return 关闭结果
     */
    boolean closePayment(String orderNo, String thirdPartyOrderNo);
    
    /**
     * 验证回调签名
     * 
     * @param callback 回调数据
     * @return 验证结果
     */
    boolean verifyCallback(PaymentCallback callback);
    
    /**
     * 处理回调数据
     * 
     * @param callback 回调数据
     * @return 处理结果
     */
    CallbackResult processCallback(PaymentCallback callback);
    
    /**
     * 获取配置状态
     * 
     * @return 是否已正确配置
     */
    boolean isConfigured();
    
    /**
     * 获取配置信息 (用于健康检查)
     * 
     * @return 配置信息
     */
    Map<String, String> getConfigInfo();
    
    /**
     * 回调处理结果
     */
    class CallbackResult {
        private boolean success;
        private String orderNo;
        private String thirdPartyOrderNo;
        private String thirdPartyTradeNo;
        private PaymentStatus status;
        private String message;
        private Object extraData;
        
        public CallbackResult(boolean success, String message) {
            this.success = success;
            this.message = message;
        }
        
        public static CallbackResult success(String orderNo, PaymentStatus status) {
            CallbackResult result = new CallbackResult(true, "处理成功");
            result.setOrderNo(orderNo);
            result.setStatus(status);
            return result;
        }
        
        public static CallbackResult failure(String message) {
            return new CallbackResult(false, message);
        }
        
        // Getters and Setters
        public boolean isSuccess() { return success; }
        public void setSuccess(boolean success) { this.success = success; }
        
        public String getOrderNo() { return orderNo; }
        public void setOrderNo(String orderNo) { this.orderNo = orderNo; }
        
        public String getThirdPartyOrderNo() { return thirdPartyOrderNo; }
        public void setThirdPartyOrderNo(String thirdPartyOrderNo) { this.thirdPartyOrderNo = thirdPartyOrderNo; }
        
        public String getThirdPartyTradeNo() { return thirdPartyTradeNo; }
        public void setThirdPartyTradeNo(String thirdPartyTradeNo) { this.thirdPartyTradeNo = thirdPartyTradeNo; }
        
        public PaymentStatus getStatus() { return status; }
        public void setStatus(PaymentStatus status) { this.status = status; }
        
        public String getMessage() { return message; }
        public void setMessage(String message) { this.message = message; }
        
        public Object getExtraData() { return extraData; }
        public void setExtraData(Object extraData) { this.extraData = extraData; }
    }
}
